﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using CE.Database;

/// <summary>
/// Summary description for ProviderTableListingsDB
/// </summary>
/// 
namespace CE.Provider
{
    public class ProviderTableListingsDB
    {
        public ProviderTableListingsDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public ProviderTableListings GetProviderTableListingsSingleItem(Int64 ProviderTypeId, Int64 ProviderCompanyId, string CXTableName)
        {
            ProviderTableListings _providertablelistings = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocProviderTableListingsSelectSingleItem]";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderTypeId", ProviderTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXTableName", CXTableName);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _providertablelistings = new ProviderTableListings();
                    _providertablelistings = FillDataRecord(_dt, 0);
                }
            }
            return _providertablelistings;
        }

        private ProviderTableListings FillDataRecord(DataTable myDataTable, int RowId)
        {
            ProviderTableListings providertablelist = new ProviderTableListings();
            providertablelist.CXTableId = Convert.ToInt32(myDataTable.Rows[RowId]["CXTableId"].ToString());
            providertablelist.ProviderTypeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderTypeId"].ToString());
            providertablelist.CXTableName = myDataTable.Rows[RowId]["CXTableName"].ToString();
            providertablelist.ProviderPageName = myDataTable.Rows[RowId]["ProviderPageName"].ToString();
            providertablelist.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());

            return providertablelist;
        }
    }
}
